package com.ycz.sportplay.controller;

import com.alibaba.fastjson.JSON;
import com.ycz.sportplay.bean.MainMenu;
import com.ycz.sportplay.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description
 * @ClassName MenuController
 * @Author yanchengzhi
 * @date 2022.06.16 01:03
 */
@RestController
@RequestMapping("/menu")
public class MenuController {

    @Autowired
    private MenuService menuService;

    @GetMapping("/getMenus")
    public String getAllMenus() {
        Map<String,Object> map = new HashMap<>();
        List<MainMenu> menus = menuService.getMenus();
        if(!menus.isEmpty()) {
            map.put("menus",menus);
            map.put("code",200);
        } else {
            map.put("code",300);
        }
        String res = JSON.toJSONString(map);
        return res;
    }

}
